package com.example.fengyungo.controller.user.user;

import com.example.fengyungo.constant.*;
import com.example.fengyungo.domain.pojo.Thing;
import com.example.fengyungo.result.Result;
import com.example.fengyungo.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.Set;

@RestController
@RequestMapping("/user/user")
public class UserThingController {

    @Autowired
    private ThingService thingService;

    /**
     * 根据货物编号获取货物信息
     *
     * @param number 货物编号
     * @return Result<Thing>
     */
    @GetMapping("/thing/{number}")
    @Cacheable(value = "thing", key = "'getThingByNumber'+#number")
    public Result<Thing> getThingByNumber(@PathVariable String number) {
        Thing thing = thingService.getThingByNumber(number);
        if (thing == null) {
            return Result.error(ThingConstant.THING_NOT_EXIST);
        }
        return Result.success(thing);
    }

}
